public class num206 {
    public ListNode reverseList(ListNode head) {
       ListNode dummyhead = new ListNode();
       ListNode prev = head;
       while (prev != null){
          ListNode node = new ListNode(prev.val);
          node.next = dummyhead.next;
          dummyhead.next = node;
          prev = prev.next;
       }
       return dummyhead.next;
    }
}
